using Microsoft.VisualBasic;
using Microsoft.VisualBasic.CompilerServices;
using SJVars;
using SJZip;
using Spacejock;
using System;
using System.Collections;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
using yW5Lib;
using yWriter6.My.Resources;

namespace yWriter6
{
	[DesignerGenerated]
	internal class frmBackupViewer : Form
	{
		private IContainer components;

		public ToolTip ToolTip1;

		[CompilerGenerated]
		[AccessedThroughProperty("clmScene")]
		private ColumnHeader _clmScene;

		[CompilerGenerated]
		[AccessedThroughProperty("ListView1")]
		private ListView _ListView1;

		[CompilerGenerated]
		[AccessedThroughProperty("cmdExit")]
		private Button _cmdExit;

		[CompilerGenerated]
		[AccessedThroughProperty("RichTextBox1")]
		private RichTextBox _RichTextBox1;

		[CompilerGenerated]
		[AccessedThroughProperty("TreeView1")]
		private TreeView _TreeView1;

		[CompilerGenerated]
		[AccessedThroughProperty("Label1")]
		private Label _Label1;

		[CompilerGenerated]
		[AccessedThroughProperty("clmDate")]
		private ColumnHeader _clmDate;

		[CompilerGenerated]
		[AccessedThroughProperty("clmFilename")]
		private ColumnHeader _clmFilename;

		private clsProject cProject;

		private bool Suppress;

		[field: AccessedThroughProperty("clmScene")]
		public virtual ColumnHeader clmScene
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		public virtual ListView ListView1
		{
			[CompilerGenerated]
			get
			{
				return _ListView1;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = ListView1_SelectedIndexChanged;
				ListView listView = _ListView1;
				if (listView != null)
				{
					listView.SelectedIndexChanged -= value2;
				}
				_ListView1 = value;
				listView = _ListView1;
				if (listView != null)
				{
					listView.SelectedIndexChanged += value2;
				}
			}
		}

		public virtual Button cmdExit
		{
			[CompilerGenerated]
			get
			{
				return _cmdExit;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				EventHandler value2 = cmdExit_Click;
				Button cmdExit = _cmdExit;
				if (cmdExit != null)
				{
					cmdExit.Click -= value2;
				}
				_cmdExit = value;
				cmdExit = _cmdExit;
				if (cmdExit != null)
				{
					cmdExit.Click += value2;
				}
			}
		}

		[field: AccessedThroughProperty("RichTextBox1")]
		public virtual RichTextBox RichTextBox1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		public virtual TreeView TreeView1
		{
			[CompilerGenerated]
			get
			{
				return _TreeView1;
			}
			[MethodImpl(MethodImplOptions.Synchronized)]
			[CompilerGenerated]
			set
			{
				TreeNodeMouseClickEventHandler value2 = TreeView1_NodeClick;
				TreeViewEventHandler value3 = TreeView1_AfterSelect;
				TreeView treeView = _TreeView1;
				if (treeView != null)
				{
					treeView.NodeMouseClick -= value2;
					treeView.AfterSelect -= value3;
				}
				_TreeView1 = value;
				treeView = _TreeView1;
				if (treeView != null)
				{
					treeView.NodeMouseClick += value2;
					treeView.AfterSelect += value3;
				}
			}
		}

		[field: AccessedThroughProperty("Label1")]
		public virtual Label Label1
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("clmDate")]
		internal virtual ColumnHeader clmDate
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[field: AccessedThroughProperty("clmFilename")]
		internal virtual ColumnHeader clmFilename
		{
			get;
			[MethodImpl(MethodImplOptions.Synchronized)]
			set;
		}

		[DebuggerNonUserCode]
		protected override void Dispose(bool Disposing)
		{
			if (Disposing && components != null)
			{
				components.Dispose();
			}
			base.Dispose(Disposing);
		}

		[System.Diagnostics.DebuggerStepThrough]
		private void InitializeComponent()
		{
			components = new System.ComponentModel.Container();
			ToolTip1 = new System.Windows.Forms.ToolTip(components);
			ListView1 = new System.Windows.Forms.ListView();
			clmDate = new System.Windows.Forms.ColumnHeader();
			clmScene = new System.Windows.Forms.ColumnHeader();
			clmFilename = new System.Windows.Forms.ColumnHeader();
			cmdExit = new System.Windows.Forms.Button();
			RichTextBox1 = new System.Windows.Forms.RichTextBox();
			TreeView1 = new System.Windows.Forms.TreeView();
			Label1 = new System.Windows.Forms.Label();
			SuspendLayout();
			ListView1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			ListView1.BackColor = System.Drawing.SystemColors.Window;
			ListView1.Columns.AddRange(new System.Windows.Forms.ColumnHeader[3]
			{
				clmDate,
				clmScene,
				clmFilename
			});
			ListView1.Font = new System.Drawing.Font("Segoe UI", 10f);
			ListView1.ForeColor = System.Drawing.SystemColors.WindowText;
			ListView1.HideSelection = false;
			ListView1.Location = new System.Drawing.Point(274, 11);
			ListView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			ListView1.Name = "ListView1";
			ListView1.Size = new System.Drawing.Size(685, 186);
			ListView1.Sorting = System.Windows.Forms.SortOrder.Ascending;
			ListView1.TabIndex = 3;
			ListView1.UseCompatibleStateImageBehavior = false;
			ListView1.View = System.Windows.Forms.View.Details;
			clmDate.Text = "Date";
			clmDate.Width = 116;
			clmScene.Text = "Scene";
			clmScene.Width = 216;
			clmFilename.Text = "Filename";
			clmFilename.Width = 227;
			cmdExit.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right);
			cmdExit.BackColor = System.Drawing.SystemColors.Control;
			cmdExit.Cursor = System.Windows.Forms.Cursors.Default;
			cmdExit.Font = new System.Drawing.Font("Segoe UI", 10f);
			cmdExit.ForeColor = System.Drawing.SystemColors.ControlText;
			cmdExit.Location = new System.Drawing.Point(846, 563);
			cmdExit.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			cmdExit.Name = "cmdExit";
			cmdExit.RightToLeft = System.Windows.Forms.RightToLeft.No;
			cmdExit.Size = new System.Drawing.Size(110, 52);
			cmdExit.TabIndex = 2;
			cmdExit.Text = "Exit";
			cmdExit.UseVisualStyleBackColor = true;
			RichTextBox1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			RichTextBox1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			RichTextBox1.Font = new System.Drawing.Font("Segoe UI", 10f);
			RichTextBox1.Location = new System.Drawing.Point(274, 205);
			RichTextBox1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			RichTextBox1.Name = "RichTextBox1";
			RichTextBox1.Size = new System.Drawing.Size(686, 328);
			RichTextBox1.TabIndex = 1;
			RichTextBox1.Text = "";
			TreeView1.Anchor = (System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left);
			TreeView1.BorderStyle = System.Windows.Forms.BorderStyle.None;
			TreeView1.Font = new System.Drawing.Font("Segoe UI", 10f);
			TreeView1.HideSelection = false;
			TreeView1.Location = new System.Drawing.Point(7, 11);
			TreeView1.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			TreeView1.Name = "TreeView1";
			TreeView1.Size = new System.Drawing.Size(260, 522);
			TreeView1.Sorted = true;
			TreeView1.TabIndex = 0;
			Label1.Anchor = (System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left | System.Windows.Forms.AnchorStyles.Right);
			Label1.BackColor = System.Drawing.SystemColors.Control;
			Label1.Cursor = System.Windows.Forms.Cursors.Default;
			Label1.Font = new System.Drawing.Font("Segoe UI", 10f);
			Label1.ForeColor = System.Drawing.SystemColors.ControlText;
			Label1.Location = new System.Drawing.Point(14, 563);
			Label1.Name = "Label1";
			Label1.RightToLeft = System.Windows.Forms.RightToLeft.No;
			Label1.Size = new System.Drawing.Size(784, 56);
			Label1.TabIndex = 4;
			Label1.Text = "Highlight text with the mouse and use Ctrl-C to copy. Then you can paste the text into any scene.";
			base.AutoScaleDimensions = new System.Drawing.SizeF(7f, 17f);
			base.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
			BackColor = System.Drawing.SystemColors.Control;
			base.ClientSize = new System.Drawing.Size(969, 630);
			base.Controls.Add(ListView1);
			base.Controls.Add(cmdExit);
			base.Controls.Add(RichTextBox1);
			base.Controls.Add(TreeView1);
			base.Controls.Add(Label1);
			Cursor = System.Windows.Forms.Cursors.Default;
			DoubleBuffered = true;
			Font = new System.Drawing.Font("Segoe UI", 10f);
			base.Location = new System.Drawing.Point(4, 23);
			base.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4);
			MinimumSize = new System.Drawing.Size(798, 586);
			base.Name = "frmBackupViewer";
			RightToLeft = System.Windows.Forms.RightToLeft.No;
			base.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
			Text = "Backup Files";
			ResumeLayout(false);
		}

		public frmBackupViewer(ref clsProject ProjectClass)
		{
			base.Load += frmBackupViewer_Load;
			InitializeComponent();
			cProject = ProjectClass;
		}

		private void cmdExit_Click(object eventSender, EventArgs eventArgs)
		{
			Hide();
			cDelay.DoEvents();
		}

		private void frmBackupViewer_Load(object eventSender, EventArgs eventArgs)
		{
			//Discarded unreachable code: IL_013d, IL_0154, IL_015f, IL_016f, IL_01c9, IL_01cb, IL_01df, IL_0201
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				base.Icon = Resources.yWriter5_Ico;
				num2 = 3;
				if (Operators.CompareString(clsShared.cLang.CurrentLanguage, "English", TextCompare: false) != 0)
				{
					num2 = 4;
					clsShared.cLang.TranslateForm(this);
				}
				num2 = 5;
				Collection Subfolders = new Collection();
				num2 = 6;
				clsShared.cFile.FillFolders(cProject.AutobackupsFolder, ref Subfolders);
				num2 = 7;
				if (Subfolders.Count != 0)
				{
					num2 = 9;
					TreeView1.Nodes.Add("AutoBackups");
					num2 = 10;
					IEnumerator enumerator = Subfolders.GetEnumerator();
					while (enumerator.MoveNext())
					{
						string text = Conversions.ToString(enumerator.Current);
						num2 = 11;
						TreeView1.Nodes[0].Nodes.Add(text);
						num2 = 12;
					}
					num2 = 13;
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
					num2 = 14;
					TreeView1.Nodes[0].Expand();
					num2 = 15;
					clsShared.cFormFont.SetFormFont(this, clsShared.cSettings.sGet("FormFont", modVariables.DefaultUIFont.Name), clsShared.cSettings.sGet("UIFontSize", modVariables.DefaultUIFont.Size));
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_01ff: Could not find block for branch target IL_01cb*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		private void FillSelectedFiles(ref TreeNode ClickedNode)
		{
			//Discarded unreachable code: IL_0152, IL_0169, IL_0174, IL_0184, IL_01f6, IL_01f8, IL_020c, IL_022e
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				Suppress = true;
				num2 = 3;
				Collection AllFiles = new Collection();
				num2 = 4;
				string text = ClickedNode.Text;
				num2 = 5;
				ListView1.Items.Clear();
				num2 = 6;
				if (!clsShared.cText.StringsEqual(text, "autobackups"))
				{
					num2 = 8;
					string text2 = Path.Combine(cProject.AutobackupsFolder, text);
					num2 = 9;
					clsShared.cFile.FillFiles(text2, "*.rtf", ref AllFiles);
					num2 = 10;
					IEnumerator enumerator = AllFiles.GetEnumerator();
					while (enumerator.MoveNext())
					{
						string filename = Conversions.ToString(enumerator.Current);
						num2 = 11;
						AddToList(filename, text2);
						num2 = 12;
					}
					num2 = 13;
					if (enumerator is IDisposable)
					{
						(enumerator as IDisposable).Dispose();
					}
					num2 = 14;
					clsList clsList = new clsList();
					num2 = 15;
					Collection collection = clsList.ListFilesInZip(Path.Combine(text2, "SequentialSceneBackups.zip"));
					num2 = 16;
					IEnumerator enumerator2 = collection.GetEnumerator();
					while (enumerator2.MoveNext())
					{
						string filename2 = Conversions.ToString(enumerator2.Current);
						num2 = 17;
						AddToList(filename2, "*" + text2);
						num2 = 18;
					}
					num2 = 19;
					if (enumerator2 is IDisposable)
					{
						(enumerator2 as IDisposable).Dispose();
					}
					num2 = 20;
					cDelay.DoEvents();
					num2 = 21;
					Suppress = false;
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_022c: Could not find block for branch target IL_01f8*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		private void AddToList(string Filename, string BackupPath)
		{
			Filename = clsShared.cFile.FileOnly(Filename);
			Conversions.ToInteger(Strings.Replace(Strings.Left(Filename, Strings.InStr(Filename, " ") - 1), "Sc", ""));
			string text = Strings.Mid(Filename, Strings.InStr(Filename, " ") + 1);
			text = Strings.Left(text, Strings.InStr(text, " ") - 1);
			string text2 = clsShared.cFile.FileWithoutExt(Filename);
			string str = Strings.Mid(text2, Strings.InStrRev(text2, " ") + 1).Trim();
			str += ".rtf";
			string text3 = Strings.Mid(Filename, Strings.InStr(Filename, " ") + 1);
			text3 = Strings.Mid(text3, Strings.InStr(text3, " ") + 1);
			text3 = Strings.Left(text3, Strings.InStrRev(text3, " ") - 1).Trim();
			ListViewItem listViewItem = ListView1.Items.Add(text);
			listViewItem.SubItems.Add(text3);
			listViewItem.SubItems.Add(str);
			listViewItem.Tag = Path.Combine(BackupPath, Filename);
		}

		private void TreeView1_NodeClick(object eventSender, TreeNodeMouseClickEventArgs eventArgs)
		{
			TreeNode ClickedNode = eventArgs.Node;
			RichTextBox1.Clear();
			FillSelectedFiles(ref ClickedNode);
		}

		private void ListView1_SelectedIndexChanged(object sender, EventArgs e)
		{
			//Discarded unreachable code: IL_002a, IL_0040, IL_004b, IL_0058, IL_008e, IL_0090, IL_00a4, IL_00c6
			int num = default(int);
			int num3 = default(int);
			try
			{
				ProjectData.ClearProjectError();
				num = 2;
				int num2 = 2;
				if (!Suppress)
				{
					num2 = 4;
					if (ListView1.FocusedItem != null)
					{
						num2 = 6;
						DisplaySelectedItem();
					}
				}
			}
			catch (Exception obj) when ((obj is Exception && num != 0) & (num3 == 0))
			{
				ProjectData.SetProjectError((Exception)obj);
				/*Error near IL_00c4: Could not find block for branch target IL_0090*/;
			}
			if (num3 != 0)
			{
				ProjectData.ClearProjectError();
			}
		}

		private void DisplaySelectedItem()
		{
			string text = "";
			string TextString = "";
			text = Conversions.ToString(ListView1.FocusedItem.Tag);
			if (text.StartsWith("*"))
			{
				text = text.Substring(1);
				try
				{
					string zipFile = Path.Combine(clsShared.cFile.PathOnly(text), "SequentialSceneBackups.zip");
					TextString = new clsUnzipToString().UnzipToString(zipFile, clsShared.cFile.FileOnly(text));
				}
				catch (Exception ex)
				{
					ProjectData.SetProjectError(ex);
					Exception ex2 = ex;
					clsShared.cLog.AddAction(ex2, MethodBase.GetCurrentMethod());
					ProjectData.ClearProjectError();
				}
			}
			else
			{
				try
				{
					clsShared.cFile.LoadTextFile(text, ref TextString);
				}
				catch (Exception ex3)
				{
					ProjectData.SetProjectError(ex3);
					Exception ex4 = ex3;
					clsShared.cLog.AddAction(ex4, MethodBase.GetCurrentMethod());
					ProjectData.ClearProjectError();
				}
			}
			try
			{
				RichTextBox1.Rtf = TextString;
			}
			catch (Exception ex5)
			{
				ProjectData.SetProjectError(ex5);
				Exception ex6 = ex5;
				RichTextBox1.Text = TextString;
				ProjectData.ClearProjectError();
			}
			if (Operators.CompareString(RichTextBox1.Text.Trim(), "", TextCompare: false) == 0)
			{
				RichTextBox1.Text = "This file is empty";
			}
			RichTextBox1.ReadOnly = true;
		}

		private void TreeView1_AfterSelect(object sender, TreeViewEventArgs e)
		{
		}
	}
}
